package com.gimi.cloud.bbp.manage.controller.product;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.enums.ServiceNameConstants;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.dto.product.LogisticsCompanyDTO;
import com.gimi.cloud.bbp.manage.service.product.LogisticsCompanyService;
import com.github.pagehelper.PageInfo;

/**
 * 物流管理
 * @author zhoufuhang
 *
 */
@RestController
@RequestMapping("/logistics/company")
public class LogisticsCompanyController {
	
	@Autowired private LogisticsCompanyService service; 
	
    /**
     * 获取列表
     * @param request
     * @param response
     * @param dto 查询参数
     * @throws Exception
     */
    @RequestMapping("/list")
    public Response list(HttpServletRequest request, HttpServletResponse response,@RequestBody LogisticsCompanyDTO dto) throws Exception{
        Response resp = new Response();
        List<LogisticsCompanyDTO> bannerGroups = service.queryList(dto,true);
        PageInfo<LogisticsCompanyDTO> pageInfo = new PageInfo<>(bannerGroups);
        Map<String,Object> resData = new HashMap<>();
        resData.put(ServiceNameConstants.PAGEDATA_KEY,pageInfo);
        resp.setRes_data(resData);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        return resp;
    }

    /**
     * 获取单一的信息
     * @param request
     * @param response
     * @param dto
     * @throws Exception
     */
    @RequestMapping("/info")
    public Response info(HttpServletRequest request,HttpServletResponse response,@RequestBody LogisticsCompanyDTO dto) throws Exception{
        Response resp = new Response();
        LogisticsCompanyDTO appBannerGroup = service.load(dto,dto.getLcId());
        Map<String,Object> resData = new HashMap<>();
        resData.put("info",appBannerGroup);
        resp.setRes_data(resData);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED,"获取成功");
        return resp;
    }

    /**
     * 新增或编辑信息
     * @param request
     * @param response
     * @param dto 待保存的数据
     * @throws Exception
     */
    @RequestMapping("/saveOrUpdate")
    public Response saveOrUpdate(HttpServletRequest request,HttpServletResponse response,@RequestBody LogisticsCompanyDTO dto) throws Exception{
        Response resp = new Response();
        service.saveOrUpdate(dto);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED,"保存成功");
        return resp;
    }
    /**
     * 删除数据
     * @param request
     * @param response
     * @param dto 待删除的banner组数据
     * @throws Exception
     */
    @RequestMapping("/delete")
    private Response delete(HttpServletRequest request,HttpServletResponse response,@RequestBody LogisticsCompanyDTO dto) throws  Exception{
        Response resp = new Response();
        service.delete(dto,dto.getLcId(),false);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED,"删除成功");
        return resp;
    }


}
